﻿@model VendorModel
@inject SeoSettings seoSettings
@inject IPageHeadBuilder pagebuilder
@{
    Layout = "_ColumnsTwo";
    pagebuilder.AddTitleParts(!String.IsNullOrEmpty(Model.MetaTitle) ? Model.MetaTitle : Model.Name);
    pagebuilder.AddMetaDescriptionParts(Model.MetaDescription);
    pagebuilder.AddMetaKeywordParts(Model.MetaKeywords);

    var canonicalUrlsEnabled = seoSettings.CanonicalUrlsEnabled;
    if (canonicalUrlsEnabled)
    {
        var vendorUrl = Url.RouteUrl("Vendor", new { SeName = Model.SeName }, this.Url.ActionContext.HttpContext.Request.Scheme);
        pagebuilder.AddCanonicalUrlParts(vendorUrl);
    }
}

<div class="page vendor-page">
    <b-card class="mt-3">
        <b-row>
            <b-col xl="2" lg="3" md="4">
                <b-avatar size="6rem" alt="@Model.PictureModel.AlternateText" src="@Model.PictureModel.ImageUrl">
            </b-col>
            <b-col xl="10" lg="9" md="8" class="align-items-center d-flex">
                <div>
                    <h1 class="h2 generalTitle w-100">
                        @Model.Name
                    </h1>
                    @if (Model.AllowCustomersToContactVendors)
                    {
                        <b-button variant="info" size="sm" class="contact-vendor-button float-xs-right" onclick="location = ('@Url.RouteUrl("ContactVendor", new { vendorId = Model.Id })')">
                            @T("ContactVendor")
                        </b-button>
                    }
                    @await Component.InvokeAsync("Widget", new { widgetZone = "vendordetails_top", additionalData = Model.Id })
                    @*description*@
                    @if (!String.IsNullOrWhiteSpace(Model.Description))
                    {
                        <article class="text-xs-center generalMarginSupporter vendor-description">
                            @Html.Raw(Model.Description)
                        </article>
                    }
                    @*review*@
                    @if (Model.VendorReviewOverview.AllowCustomerReviews)
                    {
                        <div>
                            <partial name="_VendorReviewOverview" model="Model.VendorReviewOverview" />
                        </div>
                    }
                </div>
            </b-col>
        </b-row>
        <b-row>
            <b-col cols="12">
                    @if (Model.Address != null)
                    {
                            <ul class="info px-0 mb-0">
                                @if (Model.Address.CompanyEnabled && !String.IsNullOrEmpty(Model.Address.Company))
                                {
                                    <li class="company">
                                        <label class="col-form-label">@T("Address.Fields.Company"):</label>
                                        @Model.Address.Company
                                    </li>
                                }
                                @if (Model.Address.StreetAddressEnabled && !String.IsNullOrEmpty(Model.Address.Address1))
                                {
                                    <li class="address1">
                                        <label class="col-form-label w-100">@T("Address.Fields.Address1"):</label>
                                        @Model.Address.Address1
                                    </li>
                                }
                                @if (Model.Address.StreetAddress2Enabled && !String.IsNullOrEmpty(Model.Address.Address2))
                                {
                                    <li class="address2">
                                        <label class="col-form-label">@T("Address.Fields.Address2"):</label>
                                        @Model.Address.Address2
                                    </li>
                                }
                                @if (Model.Address.CityEnabled || Model.Address.StateProvinceEnabled || Model.Address.ZipPostalCodeEnabled)
                                {
                                    var cityStateZip = "";
                                    if (Model.Address.CityEnabled && !String.IsNullOrEmpty(Model.Address.City))
                                    {
                                        cityStateZip = Model.Address.City;
                                        if (Model.Address.StateProvinceEnabled || Model.Address.ZipPostalCodeEnabled)
                                        {
                                            cityStateZip += ",";
                                        }
                                    }
                                    if (Model.Address.StateProvinceEnabled)
                                    {
                                        if (!String.IsNullOrEmpty(cityStateZip))
                                        {
                                            cityStateZip += " ";
                                        }
                                        cityStateZip += Model.Address.StateProvinceName;
                                    }
                                    if (Model.Address.ZipPostalCodeEnabled)
                                    {
                                        if (!String.IsNullOrEmpty(cityStateZip))
                                        {
                                            cityStateZip += " ";
                                        }
                                        cityStateZip += Model.Address.ZipPostalCode;
                                    }
                                    if (!String.IsNullOrEmpty(cityStateZip))
                                    {
                                        <li class="city-state-zip">
                                            @cityStateZip
                                        </li>
                                    }
                                }
                                @if (Model.Address.CountryEnabled && !String.IsNullOrEmpty(Model.Address.CountryName))
                                {
                                    <li class="country">
                                        @Model.Address.CountryName
                                    </li>
                                }
                                @if (Model.Address.PhoneEnabled && !String.IsNullOrEmpty(Model.Address.PhoneNumber))
                                {
                                    <li class="phone">
                                        <label class="col-form-label">@T("Address.Fields.PhoneNumber"):</label>
                                        @Model.Address.PhoneNumber
                                    </li>
                                }
                                @if (Model.Address.FaxEnabled && !String.IsNullOrEmpty(Model.Address.FaxNumber))
                                {
                                    <li class="fax">
                                        <label class="col-form-label">@T("Address.Fields.FaxNumber"):</label>
                                        @Model.Address.FaxNumber
                                    </li>
                                }
                            </ul>
                    }
            </b-col>
        </b-row>
    </b-card>
    @*contact vendor*@
    @if (Model.Products.Any())
    {
        <partial name="_CatalogSelectors" model="Model.PagingFilteringContext" />
    }

    @*product list*@
    @if (Model.Products.Any())
    {
        if (Model.PagingFilteringContext.ViewMode == "grid")
        {
            <b-col cols="12" class="product-grid px-0">
                <b-form-row>
                    @foreach (var product in Model.Products)
                    {
                        <b-col lg="4" sm="6" cols="6" class="product-container mb-2">
                            <partial name="_ProductBox" model="product" />
                        </b-col>
                    }
                </b-form-row>
                <page-navigation asp-query-param="pagenumber" asp-pagination="Model.PagingFilteringContext" />
            </b-col>
        }
        else
        {
            <div class="product-grid">
                <b-col cols="12">
                    <b-row class="row">
                        @foreach (var product in Model.Products)
                        {
                            <partial name="_ProductBoxList" model="product" />
                        }
                        <page-navigation asp-query-param="pagenumber" asp-pagination="Model.PagingFilteringContext" />
                    </b-row>
                </b-col>
            </div>
        }
    }
</div>

@await Component.InvokeAsync("Widget", new { widgetZone = "vendordetails_bottom", additionalData = Model.Id })

@section filters
{
    @*filtering*@
    @if (Model.PagingFilteringContext.PriceRangeFilter.Enabled)
    {
        <partial name="_FilterPriceBox" model="Model.PagingFilteringContext.PriceRangeFilter" />
    }
    @*filtering*@
    @if (Model.PagingFilteringContext.SpecificationFilter.Enabled)
    {
        <partial name="_FilterSpecsBox" model="Model.PagingFilteringContext.SpecificationFilter" />
    }
}